package com.codrim.cs.data.server.dao.entity;

import com.codrim.cs.data.rpc.dto.result.WholeDayDataResultDTO;

import java.util.Optional;

import lombok.Data;

/**
 * @author Liang.Zhuge
 * @date 28/07/2017
 */
@Data
public class DailyDataRecordDO {
    private String sdate;
    private String symbol;
    private Integer clicks;
    private Integer uniqueClicks;
    private Integer grossConversions;
    private Float revenue;
    private Float cost;
    private Integer conversions;
    private Integer sc;
    private Integer companyId;

    public WholeDayDataResultDTO toWholeDayDataResultDTO() {
        final WholeDayDataResultDTO dto = new WholeDayDataResultDTO();
        dto.setSdate(Integer.valueOf(this.sdate.replaceAll("-", "").replaceAll(" ", "")));
        dto.setSymbol(this.symbol);
        dto.setClick(Long.valueOf(Optional.ofNullable(this.clicks).orElse(0)));
        dto.setUclick(Long.valueOf(Optional.ofNullable(this.uniqueClicks).orElse(0)));
        dto.setGc(Long.valueOf(Optional.ofNullable(this.getGrossConversions()).orElse(0)));
        dto.setConversion(Long.valueOf(Optional.ofNullable(this.conversions).orElse(0)));
        dto.setAprice(Optional.ofNullable(this.revenue).orElse(0.0f));
        dto.setPprice(Optional.ofNullable(this.cost).orElse(0.0f));
        dto.setCompanyId(companyId);
        return dto;
    }
}
